/*
    x y 向下整除2^k
    k的值每次只能选择1次
    
    位运算从低位开始，每当有1位不同，累加答案
*/
#include <cstdio> 
#include <cstring>
#include <algorithm>
using namespace std;
template <typename T>
inline void read(T& x)
{
    int c=getchar(), f=1; x=0;
    while(c<'0'||'9'<c) {if(c=='-') f=-1; c=getchar();}
    while('0'<=c&&c<='9') 
        x=(x<<3)+(x<<1)+c-'0', c=getchar();
    x*=f;
}

inline void write(long long x)
{
    if(x>=10) write(x/10);
    putchar(x%10+'0');
}
#define DEBUG
using ll=long long;
const int N=60;
ll x, y, INF;
ll dp[N][N]; //dp[i][j]:k次幂的第一组和是i，第二组和是j
ll ans;

void init()
{
    memset(dp, 0x3f, sizeof dp);
    memset(&INF, 0x3f, sizeof INF);
    dp[0][0]=0;
    for(int x=0; x<N; x++) //转移媒介 2^(i+x)==2^i*2^x
        for(int i=N-1; i>=0; i--)
            for(int j=N-1; j>=0; j--)
            {
                if(dp[i][j]==INF) continue;
                if(i+x<N) dp[i+x][j]=min(dp[i+x][j], dp[i][j]+(1ll<<x));
                if(j+x<N) dp[i][j+x]=min(dp[i][j+x], dp[i][j]+(1ll<<x));

            }
}   

void solve()
{  
    read(x); read(y);
    ans=INF;
    for(int i=0; i<N; i++)
        for(int j=0; j<N; j++)
            if((x>>i)==(y>>j)) ans=min(ans, dp[i][j]);
    
    write(ans); puts("");
}

// #undef DEBUG
signed main()
{
    #ifdef DEBUG
        freopen("../in.txt", "r", stdin);
        freopen("../out.txt", "w", stdout);
    #endif
    init();
    int T=1; scanf("%d", &T);
    while(T--) 
    {
        solve();
    }
    return 0;
}